﻿<!-- model IEnumerable<JustMVCTest.Models.Papi_Users> -->
<!-- model IEnumerable<JustMVCTest.Models.WrapperModel> -->

@model JustMVCTest.Models.WrapperModel

@{ Html.Telerik().TabStrip()
        .Name("TabStrip")
        .Items(tabstrip =>
        {

            tabstrip.Add()
                .Text("PAPI_Users")
                .Content(@<text>
                    @RenderPapi_Users()

                    <script type="text/javascript">
                        function onDataBound() {
                            var grid = $(this).data('tGrid');

                            // Get the export link as jQuery object
                            var $exportLink = $('#exportCurrentToCSV');

                            // Get its 'href' attribute - the URL where it would navigate to
                            var href = $exportLink.attr('href');

                            // Update the 'page' parameter with the grid's current page
                            href = href.replace(/page=([^&]*)/, 'page=' + grid.currentPage);

                            // Update the 'orderBy' parameter with the grids' current sort state
                            href = href.replace(/orderBy=([^&]*)/, 'orderBy=' + (grid.orderBy || '~'));

                            // Update the 'filter' parameter with the grids' current filtering state
                            href = href.replace(/filter=(.*)/, 'filter=' + (grid.filterBy || '~'));

                            // Update the 'href' attribute
                            $exportLink.attr('href', href);
                        }
                    </script> 

                </text>);
            tabstrip.Add()
                .Text("POes")
                .Content(@<text>
                    @RenderPOes()
                </text>);

            tabstrip.Add()
            .Text("Background process")
            .Content(@<text>
                    @RenderPapiImport()
                </text>);
    
        })
        .SelectedIndex(0)
        .Render();
} 


@helper RenderPapi_Users()
    {
    @(Html.Telerik().Grid<JustMVCTest.Models.Papi_Users>(Model.Papi_Users)
        .Name("Papi_UsersGrid")
        .DataKeys(keys =>
        {
            keys.Add(p => p.domain_username);
        })

        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image))
        .ToolBar(commands => commands
                    .Custom()
                        .HtmlAttributes(new { id = "exportCurrentToCSV" })
                        .Text("Export current to CSV")
                        .Action("Papi_UsersExportCurrentToCsv", "Maintenance", new { page = 1, orderBy = "~", filter = "~" })
                )
         .ToolBar(commands => commands
                            .Custom()
                                .HtmlAttributes(new { id = "exportTableToCSV" })
                                .Text("Export table to CSV")
                                .Action("Papi_UsersExportTableToCsv", "Maintenance")
                        )

            //.ToolBar(commands => commands.Insert().ButtonType(type).ImageHtmlAttributes(new {style="margin-left:0"}))
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
                .Select("Papi_UsersSelectAjaxEditing", "Maintenance")
                .Insert("Papi_UsersInsertAjaxEditing", "Maintenance")
                .Update("Papi_UsersSaveAjaxEditing", "Maintenance")
                .Delete("Papi_UsersDeleteAjaxEditing", "Maintenance");
        })

        .ClientEvents(events => events.OnDataBound("onDataBound"))

        .Columns(columns =>
        {
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.Image);
                commands.Delete().ButtonType(GridButtonType.Image);
            }).Width(100).Title("Commands");

            columns.Bound(o => o.domain_username).Width(70);
            columns.Bound(o => o.email).Width(100);
            columns.Bound(o => o.First_Name).Width(80);
            columns.Bound(o => o.Last_Name).Width(80);
            columns.Bound(o => o.Requisitio).Width(70);
            columns.Bound(o => o.is_admin).Width(50);
            columns.Bound(o => o.is_superuser).Width(50);
            columns.Bound(o => o.is_tssc).Width(50);
            columns.Bound(o => o.Cost_Cent).Width(80);
            columns.Bound(o => o.Int_Order).Width(80);
            columns.Bound(o => o.filter).Width(1300);
        })

        //.Editable(editing => editing.Mode(mode).InsertRowPosition(insertRowPosition))
        .Pageable()
        .Scrollable(c => c.Height("370px"))
        .Sortable()
        .Resizable(resizing => resizing.Columns(true))
        .Filterable()
    )
}

@helper RenderPOes()
    {
    @(Html.Telerik().Grid<JustMVCTest.Models.PO>(Model.pO)
        .Name("POesGrid")
        .DataKeys(keys =>
        {
            keys.Add(p => p.PONumber).RouteKey("PONumber");
            keys.Add(p => p.Item).RouteKey("Item");
            keys.Add(p => p.Update_Num).RouteKey("Update_Num");
        })
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image))
        .DataBinding(dataBinding =>
        {
            //dataBinding.Server()
            dataBinding.Ajax()
                .Select("POesSelectAjaxEditing", "Maintenance")
                .Insert("POesInsertAjaxEditing", "Maintenance")
                .Update("POesSaveAjaxEditing", "Maintenance")
                .Delete("POesDeleteAjaxEditing", "Maintenance");
        })

        .Columns(columns =>
        {

            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.Image);
                commands.Delete().ButtonType(GridButtonType.Image);
            }).Width(100).Title("Commands");

            columns.Bound(o => o.PONumber).Width(130);
            columns.Bound(o => o.Item).Width(50);
            columns.Bound(o => o.Update_Num).Width(50);
            columns.Bound(o => o.latest).Width(30);
            columns.Bound(o => o.Status).Width(100);//.Format("{0:N}");
            columns.Bound(o => o.TSSC_Pending_Send_Date).Width(150);
            columns.Bound(o => o.Purchase_O).Width(130);
            columns.Bound(o => o.Requisitioner).Width(100);
            columns.Bound(o => o.DeliveryDate).Width(130).Format("{0:d}");
            columns.Bound(o => o.DeliveryDate_Req).Width(130).Format("{0:d}");
            columns.Bound(o => o.Cost_Cent).Width(150);
            columns.Bound(o => o.Int_Order).Width(150);

            columns.Bound(o => o.Prof_Cent).Width(100);
            columns.Bound(o => o.Percentage).Width(100);
            columns.Bound(o => o.Percentage_Update_Date).Width(130);
            columns.Bound(o => o.cost_elem).Width(100);
            columns.Bound(o => o.co_el_name).Width(200);
            columns.Bound(o => o.Vendor).Width(100);
            columns.Bound(o => o.VendorName).Width(300);
            columns.Bound(o => o.Descr).Width(600);
            columns.Bound(o => o.UM).Width(100);
            columns.Bound(o => o.T_Curr).Width(100);
            columns.Bound(o => o.Sch_Lin).Width(100);

            columns.Bound(o => o.Ord_Qty).Width(100);
            columns.Bound(o => o.Open_Qty).Width(100);
            columns.Bound(o => o.Open_Amt_T).Width(100);
            columns.Bound(o => o.Order_Amt).Width(100);
            columns.Bound(o => o.Open_Amt_L).Width(100);
            columns.Bound(o => o.Insert_Date).Width(250).Format("{0:dd/MM/yyyy HH:mm:ss}");
            columns.Bound(o => o.Update_Date).Width(250).Format("{0:dd/MM/yyyy HH:mm:ss}");

            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.Image);
                commands.Delete().ButtonType(GridButtonType.Image);
            }).Width(100).Title("Commands");

        })
        .Pageable()
        .Scrollable(c => c.Height("370px"))
        .Sortable()
        .Resizable(resizing => resizing.Columns(true))
        .Filterable()


    )    
}




@helper RenderPapiImport()
{
    
    <!-- <script type="text/javascript">
        
        function LaunchCalc()
        {
            $.ajax({
                url: '/BackgroundProcess/',
                data: { }
                success: function()
                {
                alert('Added');      
                }
            });
        }
     </script> -->
    
    <script src="@Url.Content("~/Scripts/2012.2.607/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <!--
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
    -->
    
    <!--
        $(document).ready
        (
            function () {
                $("#btn1").click
                (
                    function () {
                        alert("my shit1");
                        $.post('/Maintenance/serverJsonMethod', {}, function (data) {
                            $("#div1").html(data["someProperty"]);
                            alert("fsdfsdfs");
                        });
                        alert("my shit2");
                    }
                );
            }
        );
    -->
    
    <script type="text/javascript">
        $(document).ready(function () { $("#btn1").click(function () { $.post('/Maintenance/LaunchPapiImport', { workmode: 1 }, function (data) { $("#div1").html(data); }); }); });
        $(document).ready(function () { $("#btn2").click(function () { $.post('/Maintenance/LaunchPapiImport', { workmode: 2 }, function (data) { $("#div2").html(data); }); }); });
        $(document).ready(function () { $("#btn3").click(function () { $.post('/Maintenance/LaunchPapiImport', { workmode: 3 }, function (data) { $("#div3").html(data); }); }); });
        $(document).ready(function () { $("#btn4").click(function () { $.post('/Maintenance/LaunchPapiImport', { workmode: 4 }, function (data) { $("#div4").html(data); }); }); });
        $(document).ready(function () { $("#btn5").click(function () { $.post('/Maintenance/LaunchPapiImport', { workmode: 5 }, function (data) { $("#div5").html(data); }); }); });
        $(document).ready(function () { $("#btn6").click(function () { $.post('/Maintenance/LaunchPapiImport', { workmode: 6 }, function (data) { $("#div6").html(data); }); }); });
        $(document).ready(function () { $("#btn7").click(function () { $.post('/Maintenance/LaunchPapiImport', { workmode: 7 }, function (data) { $("#div7").html(data); }); }); });
        $(document).ready(function () { $("#btn8").click(function () { $.post('/Maintenance/LaunchNotepad', {}, function (data) { $("#div8").html(data); }); }); });
    </script>

    <h3>Use at your own risk</h3>
    
    <table border="1">
      <tr>
        <th>Workmode</th>
        <th>Result</th>
      </tr>
      <tr>
        <td><button id="btn1">Workmode 1</button></td>
        <td><div id="div1"></div></td>
      </tr>
      <tr>
        <td><button id="btn2">Workmode 2</button></td>
        <td><div id="div2"></div></td>
      </tr>
      <tr>
        <td><button id="btn3">Workmode 3</button></td>
        <td><div id="div3"></div></td>
      </tr>
      <tr>
        <td><button id="btn4">Workmode 4</button></td>
        <td><div id="div4"></div></td>
      </tr>
      <tr>
        <td><button id="btn5">Workmode 5</button></td>
        <td><div id="div5"></div></td>
      </tr>
      <tr>
        <td><button id="btn6">Workmode 6</button></td>
        <td><div id="div6"></div></td>
      </tr>
      <tr>
        <td><button id="btn7">Workmode 7</button></td>
        <td><div id="div7"></div></td>
      </tr>
      <tr>
        <td><button id="btn8">Notepad</button></td>
        <td><div id="div8"></div></td>
      </tr>
    </table> 
    
    <br />
  
}